<?php
ArrowController::importModel("org.arrowplatform.controls.presentation.table.columns.ArrowAbstractTableColumn");
class ArrowTableStandardColumn extends ArrowAbstractTableColumn{
	private $width;
	private $simpleField;
	private $viewFormat;
	//private $mapping;
	
	public function configure(){
		parent::configure();
		$this->addProperties(array(
			"viewType" => false
		));
		$this->setContentCodeKept(true);
	}
	
	public function init(){
		parent::init();
		$this->width = $this->getProperty("width");
		
		$this->mapping = $this->getProperty("mapping");
		
		if(strpos($this->field, ";") !== false){
			$ex = explode(";", $this->field);
			$this->simpleField = $ex;	
		}else{
			$this->simpleField = $this->field;
		}
		
		$this->viewFormat = $this->getProperty("viewType");
		
	}

	public function generateRowCell( $context ){
		
		
		if(is_array($this->simpleField)){
			$val = "";
			foreach( $this->simpleField as $_field)
				$val.= $context->getValue($_field)." ";
		}else
			$val = $context->getValue($this->simpleField);
		
		 
			
		if(isset($this->mapping[$val]))
			$val = $this->mapping[$val];
		if($this->width != -1) {
			if( $this->viewFormat == "date" ) {
				$val = preg_replace( "/([0-9]{2})\:([0-9]{2})\:([0-9]{2})/i", "$1:$2", $val );
			} 
			
			return  "<td {$this->class} >".$this->getImage($context).$val."</td>";
		}
		return "";
	}

}

?>